<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - code analysis - src/caffe/data_transformer.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">src/caffe</a> - data_transformer.cpp<span style="font-size: 80%;"> (source / <a href="data_transformer.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">code analysis</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">56</td>
            <td class="headerCovTableEntry">265</td>
            <td class="headerCovTableEntryLo">21.1 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2020-09-11 22:50:33</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">7</td>
            <td class="headerCovTableEntry">28</td>
            <td class="headerCovTableEntryLo">25.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #ifdef USE_OPENCV</a>
<span class="lineNum">       2 </span>            : #include &lt;opencv2/core/core.hpp&gt;
<span class="lineNum">       3 </span>            : #endif  // USE_OPENCV
<span class="lineNum">       4 </span>            : 
<span class="lineNum">       5 </span>            : #include &lt;string&gt;
<span class="lineNum">       6 </span>            : #include &lt;vector&gt;
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span>            : #include &quot;caffe/data_transformer.hpp&quot;
<span class="lineNum">       9 </span>            : #include &quot;caffe/util/io.hpp&quot;
<span class="lineNum">      10 </span>            : #include &quot;caffe/util/math_functions.hpp&quot;
<span class="lineNum">      11 </span>            : #include &quot;caffe/util/rng.hpp&quot;
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : namespace caffe {
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">      16 </span><span class="lineCov">          2 : DataTransformer&lt;Dtype&gt;::DataTransformer(const TransformationParameter&amp; param,</span>
<span class="lineNum">      17 </span>            :     Phase phase)
<span class="lineNum">      18 </span><span class="lineCov">          4 :     : param_(param), phase_(phase) {</span>
<span class="lineNum">      19 </span>            :   // check if we want to use mean_file
<span class="lineNum">      20 </span><span class="lineCov">          2 :   if (param_.has_mean_file()) {</span>
<span class="lineNum">      21 </span><span class="lineNoCov">          0 :     CHECK_EQ(param_.mean_value_size(), 0) &lt;&lt;</span>
<span class="lineNum">      22 </span>            :       &quot;Cannot specify mean_file and mean_value at the same time&quot;;
<span class="lineNum">      23 </span>            :     const string&amp; mean_file = param.mean_file();
<span class="lineNum">      24 </span><span class="lineNoCov">          0 :     if (Caffe::root_solver()) {</span>
<span class="lineNum">      25 </span><span class="lineNoCov">          0 :       LOG(INFO) &lt;&lt; &quot;Loading mean file from: &quot; &lt;&lt; mean_file;</span>
<span class="lineNum">      26 </span>            :     }
<span class="lineNum">      27 </span><span class="lineNoCov">          0 :     BlobProto blob_proto;</span>
<span class="lineNum">      28 </span><span class="lineNoCov">          0 :     ReadProtoFromBinaryFileOrDie(mean_file.c_str(), &amp;blob_proto);</span>
<span class="lineNum">      29 </span><span class="lineNoCov">          0 :     data_mean_.FromProto(blob_proto);</span>
<span class="lineNum">      30 </span>            :   }
<span class="lineNum">      31 </span>            :   // check if we want to use mean_value
<span class="lineNum">      32 </span><span class="lineCov">          2 :   if (param_.mean_value_size() &gt; 0) {</span>
<span class="lineNum">      33 </span><span class="lineNoCov">          0 :     CHECK(param_.has_mean_file() == false) &lt;&lt;</span>
<span class="lineNum">      34 </span>            :       &quot;Cannot specify mean_file and mean_value at the same time&quot;;
<span class="lineNum">      35 </span><span class="lineNoCov">          0 :     for (int c = 0; c &lt; param_.mean_value_size(); ++c) {</span>
<span class="lineNum">      36 </span><span class="lineNoCov">          0 :       mean_values_.push_back(param_.mean_value(c));</span>
<span class="lineNum">      37 </span>            :     }
<span class="lineNum">      38 </span>            :   }
<span class="lineNum">      39 </span><span class="lineCov">          2 : }</span>
<span class="lineNum">      40 </span>            : 
<span class="lineNum">      41 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">      42 </span><span class="lineCov">     850556 : void DataTransformer&lt;Dtype&gt;::Transform(const Datum&amp; datum,</span>
<span class="lineNum">      43 </span>            :                                        Dtype* transformed_data) {
<span class="lineNum">      44 </span>            :   const string&amp; data = datum.data();
<span class="lineNum">      45 </span>            :   const int datum_channels = datum.channels();
<span class="lineNum">      46 </span>            :   const int datum_height = datum.height();
<span class="lineNum">      47 </span>            :   const int datum_width = datum.width();
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span><span class="lineCov">     850556 :   const int crop_size = param_.crop_size();</span>
<span class="lineNum">      50 </span><span class="lineNoCov">          0 :   const Dtype scale = param_.scale();</span>
<span class="lineNum">      51 </span><span class="lineCov">     850556 :   const bool do_mirror = param_.mirror() &amp;&amp; Rand(2);</span>
<span class="lineNum">      52 </span>            :   const bool has_mean_file = param_.has_mean_file();
<span class="lineNum">      53 </span>            :   const bool has_uint8 = data.size() &gt; 0;
<span class="lineNum">      54 </span>            :   const bool has_mean_values = mean_values_.size() &gt; 0;
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span><span class="lineCov">     850556 :   CHECK_GT(datum_channels, 0);</span>
<span class="lineNum">      57 </span><span class="lineCov">     850556 :   CHECK_GE(datum_height, crop_size);</span>
<span class="lineNum">      58 </span><span class="lineCov">     850556 :   CHECK_GE(datum_width, crop_size);</span>
<span class="lineNum">      59 </span>            : 
<span class="lineNum">      60 </span>            :   Dtype* mean = NULL;
<span class="lineNum">      61 </span><span class="lineCov">     850556 :   if (has_mean_file) {</span>
<span class="lineNum">      62 </span><span class="lineNoCov">          0 :     CHECK_EQ(datum_channels, data_mean_.channels());</span>
<span class="lineNum">      63 </span><span class="lineNoCov">          0 :     CHECK_EQ(datum_height, data_mean_.height());</span>
<span class="lineNum">      64 </span><span class="lineNoCov">          0 :     CHECK_EQ(datum_width, data_mean_.width());</span>
<span class="lineNum">      65 </span><span class="lineNoCov">          0 :     mean = data_mean_.mutable_cpu_data();</span>
<span class="lineNum">      66 </span>            :   }
<span class="lineNum">      67 </span><span class="lineCov">     850556 :   if (has_mean_values) {</span>
<span class="lineNum">      68 </span><span class="lineNoCov">          0 :     CHECK(mean_values_.size() == 1 || mean_values_.size() == datum_channels) &lt;&lt;</span>
<span class="lineNum">      69 </span><span class="lineNoCov">          0 :      &quot;Specify either 1 mean_value or as many as channels: &quot; &lt;&lt; datum_channels;</span>
<span class="lineNum">      70 </span><span class="lineNoCov">          0 :     if (datum_channels &gt; 1 &amp;&amp; mean_values_.size() == 1) {</span>
<span class="lineNum">      71 </span>            :       // Replicate the mean_value for simplicity
<span class="lineNum">      72 </span><span class="lineNoCov">          0 :       for (int c = 1; c &lt; datum_channels; ++c) {</span>
<span class="lineNum">      73 </span><span class="lineNoCov">          0 :         mean_values_.push_back(mean_values_[0]);</span>
<span class="lineNum">      74 </span>            :       }
<span class="lineNum">      75 </span>            :     }
<span class="lineNum">      76 </span>            :   }
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span>            :   int height = datum_height;
<span class="lineNum">      79 </span>            :   int width = datum_width;
<span class="lineNum">      80 </span>            : 
<span class="lineNum">      81 </span>            :   int h_off = 0;
<span class="lineNum">      82 </span>            :   int w_off = 0;
<span class="lineNum">      83 </span><span class="lineCov">     850556 :   if (crop_size) {</span>
<span class="lineNum">      84 </span>            :     height = crop_size;
<span class="lineNum">      85 </span>            :     width = crop_size;
<span class="lineNum">      86 </span>            :     // We only do random crop when we do training.
<span class="lineNum">      87 </span><span class="lineNoCov">          0 :     if (phase_ == TRAIN) {</span>
<span class="lineNum">      88 </span><span class="lineNoCov">          0 :       h_off = Rand(datum_height - crop_size + 1);</span>
<span class="lineNum">      89 </span><span class="lineNoCov">          0 :       w_off = Rand(datum_width - crop_size + 1);</span>
<span class="lineNum">      90 </span>            :     } else {
<span class="lineNum">      91 </span><span class="lineNoCov">          0 :       h_off = (datum_height - crop_size) / 2;</span>
<span class="lineNum">      92 </span><span class="lineNoCov">          0 :       w_off = (datum_width - crop_size) / 2;</span>
<span class="lineNum">      93 </span>            :     }
<span class="lineNum">      94 </span>            :   }
<span class="lineNum">      95 </span>            : 
<span class="lineNum">      96 </span>            :   Dtype datum_element;
<span class="lineNum">      97 </span>            :   int top_index, data_index;
<span class="lineNum">      98 </span><span class="lineCov">    2551668 :   for (int c = 0; c &lt; datum_channels; ++c) {</span>
<span class="lineNum">      99 </span><span class="lineCov">   48481692 :     for (int h = 0; h &lt; height; ++h) {</span>
<span class="lineNum">     100 </span><span class="lineCov"> 1357487376 :       for (int w = 0; w &lt; width; ++w) {</span>
<span class="lineNum">     101 </span><span class="lineCov">  666835904 :         data_index = (c * datum_height + h_off + h) * datum_width + w_off + w;</span>
<span class="lineNum">     102 </span><span class="lineCov">  666835904 :         if (do_mirror) {</span>
<span class="lineNum">     103 </span><span class="lineNoCov">          0 :           top_index = (c * height + h) * width + (width - 1 - w);</span>
<span class="lineNum">     104 </span>            :         } else {
<span class="lineNum">     105 </span><span class="lineCov">  666835904 :           top_index = (c * height + h) * width + w;</span>
<span class="lineNum">     106 </span>            :         }
<span class="lineNum">     107 </span><span class="lineCov">  666835904 :         if (has_uint8) {</span>
<span class="lineNum">     108 </span><span class="lineCov"> 1333671808 :           datum_element =</span>
<span class="lineNum">     109 </span>            :             static_cast&lt;Dtype&gt;(static_cast&lt;uint8_t&gt;(data[data_index]));
<span class="lineNum">     110 </span>            :         } else {
<span class="lineNum">     111 </span><span class="lineNoCov">          0 :           datum_element = datum.float_data(data_index);</span>
<span class="lineNum">     112 </span>            :         }
<span class="lineNum">     113 </span><span class="lineCov">  666835904 :         if (has_mean_file) {</span>
<span class="lineNum">     114 </span><span class="lineNoCov">          0 :           transformed_data[top_index] =</span>
<span class="lineNum">     115 </span><span class="lineNoCov">          0 :             (datum_element - mean[data_index]) * scale;</span>
<span class="lineNum">     116 </span>            :         } else {
<span class="lineNum">     117 </span><span class="lineCov">  666835904 :           if (has_mean_values) {</span>
<span class="lineNum">     118 </span><span class="lineNoCov">          0 :             transformed_data[top_index] =</span>
<span class="lineNum">     119 </span><span class="lineNoCov">          0 :               (datum_element - mean_values_[c]) * scale;</span>
<span class="lineNum">     120 </span>            :           } else {
<span class="lineNum">     121 </span><span class="lineCov">  666835904 :             transformed_data[top_index] = datum_element * scale;</span>
<span class="lineNum">     122 </span>            :           }
<span class="lineNum">     123 </span>            :         }
<span class="lineNum">     124 </span>            :       }
<span class="lineNum">     125 </span>            :     }
<span class="lineNum">     126 </span>            :   }
<span class="lineNum">     127 </span><span class="lineCov">     850556 : }</span>
<span class="lineNum">     128 </span>            : 
<a name="129"><span class="lineNum">     129 </span>            : </a>
<span class="lineNum">     130 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     131 </span><span class="lineCov">     850556 : void DataTransformer&lt;Dtype&gt;::Transform(const Datum&amp; datum,</span>
<span class="lineNum">     132 </span>            :                                        Blob&lt;Dtype&gt;* transformed_blob) {
<span class="lineNum">     133 </span>            :   // If datum is encoded, decode and transform the cv::image.
<span class="lineNum">     134 </span><span class="lineCov">     850556 :   if (datum.encoded()) {</span>
<span class="lineNum">     135 </span>            : #ifdef USE_OPENCV
<span class="lineNum">     136 </span><span class="lineNoCov">          0 :     CHECK(!(param_.force_color() &amp;&amp; param_.force_gray()))</span>
<span class="lineNum">     137 </span>            :         &lt;&lt; &quot;cannot set both force_color and force_gray&quot;;
<span class="lineNum">     138 </span><span class="lineNoCov">          0 :     cv::Mat cv_img;</span>
<span class="lineNum">     139 </span><span class="lineNoCov">          0 :     if (param_.force_color() || param_.force_gray()) {</span>
<span class="lineNum">     140 </span>            :     // If force_color then decode in color otherwise decode in gray.
<span class="lineNum">     141 </span><span class="lineNoCov">          0 :       cv_img = DecodeDatumToCVMat(datum, param_.force_color());</span>
<span class="lineNum">     142 </span>            :     } else {
<span class="lineNum">     143 </span><span class="lineNoCov">          0 :       cv_img = DecodeDatumToCVMatNative(datum);</span>
<span class="lineNum">     144 </span>            :     }
<span class="lineNum">     145 </span>            :     // Transform the cv::image into blob.
<span class="lineNum">     146 </span><span class="lineNoCov">          0 :     return Transform(cv_img, transformed_blob);</span>
<span class="lineNum">     147 </span>            : #else
<span class="lineNum">     148 </span>            :     LOG(FATAL) &lt;&lt; &quot;Encoded datum requires OpenCV; compile with USE_OPENCV.&quot;;
<span class="lineNum">     149 </span>            : #endif  // USE_OPENCV
<span class="lineNum">     150 </span>            :   } else {
<span class="lineNum">     151 </span><span class="lineCov">     850556 :     if (param_.force_color() || param_.force_gray()) {</span>
<span class="lineNum">     152 </span><span class="lineNoCov">          0 :       LOG(ERROR) &lt;&lt; &quot;force_color and force_gray only for encoded datum&quot;;</span>
<span class="lineNum">     153 </span>            :     }
<span class="lineNum">     154 </span>            :   }
<span class="lineNum">     155 </span>            : 
<span class="lineNum">     156 </span><span class="lineCov">     850556 :   const int crop_size = param_.crop_size();</span>
<span class="lineNum">     157 </span>            :   const int datum_channels = datum.channels();
<span class="lineNum">     158 </span>            :   const int datum_height = datum.height();
<span class="lineNum">     159 </span>            :   const int datum_width = datum.width();
<span class="lineNum">     160 </span>            : 
<span class="lineNum">     161 </span>            :   // Check dimensions.
<span class="lineNum">     162 </span>            :   const int channels = transformed_blob-&gt;channels();
<span class="lineNum">     163 </span>            :   const int height = transformed_blob-&gt;height();
<span class="lineNum">     164 </span>            :   const int width = transformed_blob-&gt;width();
<span class="lineNum">     165 </span>            :   const int num = transformed_blob-&gt;num();
<span class="lineNum">     166 </span>            : 
<span class="lineNum">     167 </span><span class="lineCov">     850556 :   CHECK_EQ(channels, datum_channels);</span>
<span class="lineNum">     168 </span><span class="lineCov">     850556 :   CHECK_LE(height, datum_height);</span>
<span class="lineNum">     169 </span><span class="lineCov">     850556 :   CHECK_LE(width, datum_width);</span>
<span class="lineNum">     170 </span><span class="lineCov">     850556 :   CHECK_GE(num, 1);</span>
<span class="lineNum">     171 </span>            : 
<span class="lineNum">     172 </span><span class="lineCov">     850556 :   if (crop_size) {</span>
<span class="lineNum">     173 </span><span class="lineNoCov">          0 :     CHECK_EQ(crop_size, height);</span>
<span class="lineNum">     174 </span><span class="lineNoCov">          0 :     CHECK_EQ(crop_size, width);</span>
<span class="lineNum">     175 </span>            :   } else {
<span class="lineNum">     176 </span><span class="lineCov">     850556 :     CHECK_EQ(datum_height, height);</span>
<span class="lineNum">     177 </span><span class="lineCov">     850556 :     CHECK_EQ(datum_width, width);</span>
<span class="lineNum">     178 </span>            :   }
<span class="lineNum">     179 </span>            : 
<span class="lineNum">     180 </span><span class="lineCov">     850556 :   Dtype* transformed_data = transformed_blob-&gt;mutable_cpu_data();</span>
<span class="lineNum">     181 </span><span class="lineCov">     850556 :   Transform(datum, transformed_data);</span>
<span class="lineNum">     182 </span>            : }
<span class="lineNum">     183 </span>            : 
<span class="lineNum">     184 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     185 </span><span class="lineNoCov">          0 : void DataTransformer&lt;Dtype&gt;::Transform(const vector&lt;Datum&gt; &amp; datum_vector,</span>
<span class="lineNum">     186 </span>            :                                        Blob&lt;Dtype&gt;* transformed_blob) {
<span class="lineNum">     187 </span><span class="lineNoCov">          0 :   const int datum_num = datum_vector.size();</span>
<span class="lineNum">     188 </span>            :   const int num = transformed_blob-&gt;num();
<span class="lineNum">     189 </span>            :   const int channels = transformed_blob-&gt;channels();
<span class="lineNum">     190 </span>            :   const int height = transformed_blob-&gt;height();
<span class="lineNum">     191 </span>            :   const int width = transformed_blob-&gt;width();
<span class="lineNum">     192 </span>            : 
<span class="lineNum">     193 </span><span class="lineNoCov">          0 :   CHECK_GT(datum_num, 0) &lt;&lt; &quot;There is no datum to add&quot;;</span>
<span class="lineNum">     194 </span><span class="lineNoCov">          0 :   CHECK_LE(datum_num, num) &lt;&lt;</span>
<span class="lineNum">     195 </span>            :     &quot;The size of datum_vector must be no greater than transformed_blob-&gt;num()&quot;;
<span class="lineNum">     196 </span><span class="lineNoCov">          0 :   Blob&lt;Dtype&gt; uni_blob(1, channels, height, width);</span>
<span class="lineNum">     197 </span><span class="lineNoCov">          0 :   for (int item_id = 0; item_id &lt; datum_num; ++item_id) {</span>
<span class="lineNum">     198 </span><span class="lineNoCov">          0 :     int offset = transformed_blob-&gt;offset(item_id);</span>
<span class="lineNum">     199 </span><span class="lineNoCov">          0 :     uni_blob.set_cpu_data(transformed_blob-&gt;mutable_cpu_data() + offset);</span>
<span class="lineNum">     200 </span><span class="lineNoCov">          0 :     Transform(datum_vector[item_id], &amp;uni_blob);</span>
<span class="lineNum">     201 </span>            :   }
<span class="lineNum">     202 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     203 </span>            : 
<span class="lineNum">     204 </span>            : #ifdef USE_OPENCV
<span class="lineNum">     205 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     206 </span><span class="lineNoCov">          0 : void DataTransformer&lt;Dtype&gt;::Transform(const vector&lt;cv::Mat&gt; &amp; mat_vector,</span>
<span class="lineNum">     207 </span>            :                                        Blob&lt;Dtype&gt;* transformed_blob) {
<span class="lineNum">     208 </span><span class="lineNoCov">          0 :   const int mat_num = mat_vector.size();</span>
<span class="lineNum">     209 </span>            :   const int num = transformed_blob-&gt;num();
<span class="lineNum">     210 </span>            :   const int channels = transformed_blob-&gt;channels();
<span class="lineNum">     211 </span>            :   const int height = transformed_blob-&gt;height();
<span class="lineNum">     212 </span>            :   const int width = transformed_blob-&gt;width();
<span class="lineNum">     213 </span>            : 
<span class="lineNum">     214 </span><span class="lineNoCov">          0 :   CHECK_GT(mat_num, 0) &lt;&lt; &quot;There is no MAT to add&quot;;</span>
<span class="lineNum">     215 </span><span class="lineNoCov">          0 :   CHECK_EQ(mat_num, num) &lt;&lt;</span>
<span class="lineNum">     216 </span>            :     &quot;The size of mat_vector must be equals to transformed_blob-&gt;num()&quot;;
<span class="lineNum">     217 </span><span class="lineNoCov">          0 :   Blob&lt;Dtype&gt; uni_blob(1, channels, height, width);</span>
<span class="lineNum">     218 </span><span class="lineNoCov">          0 :   for (int item_id = 0; item_id &lt; mat_num; ++item_id) {</span>
<span class="lineNum">     219 </span><span class="lineNoCov">          0 :     int offset = transformed_blob-&gt;offset(item_id);</span>
<span class="lineNum">     220 </span><span class="lineNoCov">          0 :     uni_blob.set_cpu_data(transformed_blob-&gt;mutable_cpu_data() + offset);</span>
<span class="lineNum">     221 </span><span class="lineNoCov">          0 :     Transform(mat_vector[item_id], &amp;uni_blob);</span>
<span class="lineNum">     222 </span>            :   }
<span class="lineNum">     223 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     224 </span>            : 
<span class="lineNum">     225 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     226 </span><span class="lineNoCov">          0 : void DataTransformer&lt;Dtype&gt;::Transform(const cv::Mat&amp; cv_img,</span>
<span class="lineNum">     227 </span>            :                                        Blob&lt;Dtype&gt;* transformed_blob) {
<span class="lineNum">     228 </span><span class="lineNoCov">          0 :   const int crop_size = param_.crop_size();</span>
<span class="lineNum">     229 </span>            :   const int img_channels = cv_img.channels();
<span class="lineNum">     230 </span><span class="lineNoCov">          0 :   const int img_height = cv_img.rows;</span>
<span class="lineNum">     231 </span><span class="lineNoCov">          0 :   const int img_width = cv_img.cols;</span>
<span class="lineNum">     232 </span>            : 
<span class="lineNum">     233 </span>            :   // Check dimensions.
<span class="lineNum">     234 </span>            :   const int channels = transformed_blob-&gt;channels();
<span class="lineNum">     235 </span>            :   const int height = transformed_blob-&gt;height();
<span class="lineNum">     236 </span>            :   const int width = transformed_blob-&gt;width();
<span class="lineNum">     237 </span>            :   const int num = transformed_blob-&gt;num();
<span class="lineNum">     238 </span>            : 
<span class="lineNum">     239 </span><span class="lineNoCov">          0 :   CHECK_EQ(channels, img_channels);</span>
<span class="lineNum">     240 </span><span class="lineNoCov">          0 :   CHECK_LE(height, img_height);</span>
<span class="lineNum">     241 </span><span class="lineNoCov">          0 :   CHECK_LE(width, img_width);</span>
<span class="lineNum">     242 </span><span class="lineNoCov">          0 :   CHECK_GE(num, 1);</span>
<span class="lineNum">     243 </span>            : 
<span class="lineNum">     244 </span><span class="lineNoCov">          0 :   CHECK(cv_img.depth() == CV_8U) &lt;&lt; &quot;Image data type must be unsigned byte&quot;;</span>
<span class="lineNum">     245 </span>            : 
<span class="lineNum">     246 </span><span class="lineNoCov">          0 :   const Dtype scale = param_.scale();</span>
<span class="lineNum">     247 </span><span class="lineNoCov">          0 :   const bool do_mirror = param_.mirror() &amp;&amp; Rand(2);</span>
<span class="lineNum">     248 </span>            :   const bool has_mean_file = param_.has_mean_file();
<span class="lineNum">     249 </span>            :   const bool has_mean_values = mean_values_.size() &gt; 0;
<span class="lineNum">     250 </span>            : 
<span class="lineNum">     251 </span><span class="lineNoCov">          0 :   CHECK_GT(img_channels, 0);</span>
<span class="lineNum">     252 </span><span class="lineNoCov">          0 :   CHECK_GE(img_height, crop_size);</span>
<span class="lineNum">     253 </span><span class="lineNoCov">          0 :   CHECK_GE(img_width, crop_size);</span>
<span class="lineNum">     254 </span>            : 
<span class="lineNum">     255 </span>            :   Dtype* mean = NULL;
<span class="lineNum">     256 </span><span class="lineNoCov">          0 :   if (has_mean_file) {</span>
<span class="lineNum">     257 </span><span class="lineNoCov">          0 :     CHECK_EQ(img_channels, data_mean_.channels());</span>
<span class="lineNum">     258 </span><span class="lineNoCov">          0 :     CHECK_EQ(img_height, data_mean_.height());</span>
<span class="lineNum">     259 </span><span class="lineNoCov">          0 :     CHECK_EQ(img_width, data_mean_.width());</span>
<span class="lineNum">     260 </span><span class="lineNoCov">          0 :     mean = data_mean_.mutable_cpu_data();</span>
<span class="lineNum">     261 </span>            :   }
<span class="lineNum">     262 </span><span class="lineNoCov">          0 :   if (has_mean_values) {</span>
<span class="lineNum">     263 </span><span class="lineNoCov">          0 :     CHECK(mean_values_.size() == 1 || mean_values_.size() == img_channels) &lt;&lt;</span>
<span class="lineNum">     264 </span><span class="lineNoCov">          0 :      &quot;Specify either 1 mean_value or as many as channels: &quot; &lt;&lt; img_channels;</span>
<span class="lineNum">     265 </span><span class="lineNoCov">          0 :     if (img_channels &gt; 1 &amp;&amp; mean_values_.size() == 1) {</span>
<span class="lineNum">     266 </span>            :       // Replicate the mean_value for simplicity
<span class="lineNum">     267 </span><span class="lineNoCov">          0 :       for (int c = 1; c &lt; img_channels; ++c) {</span>
<span class="lineNum">     268 </span><span class="lineNoCov">          0 :         mean_values_.push_back(mean_values_[0]);</span>
<span class="lineNum">     269 </span>            :       }
<span class="lineNum">     270 </span>            :     }
<span class="lineNum">     271 </span>            :   }
<span class="lineNum">     272 </span>            : 
<span class="lineNum">     273 </span>            :   int h_off = 0;
<span class="lineNum">     274 </span>            :   int w_off = 0;
<span class="lineNum">     275 </span><span class="lineNoCov">          0 :   cv::Mat cv_cropped_img = cv_img;</span>
<span class="lineNum">     276 </span><span class="lineNoCov">          0 :   if (crop_size) {</span>
<span class="lineNum">     277 </span><span class="lineNoCov">          0 :     CHECK_EQ(crop_size, height);</span>
<span class="lineNum">     278 </span><span class="lineNoCov">          0 :     CHECK_EQ(crop_size, width);</span>
<span class="lineNum">     279 </span>            :     // We only do random crop when we do training.
<span class="lineNum">     280 </span><span class="lineNoCov">          0 :     if (phase_ == TRAIN) {</span>
<span class="lineNum">     281 </span><span class="lineNoCov">          0 :       h_off = Rand(img_height - crop_size + 1);</span>
<span class="lineNum">     282 </span><span class="lineNoCov">          0 :       w_off = Rand(img_width - crop_size + 1);</span>
<span class="lineNum">     283 </span>            :     } else {
<span class="lineNum">     284 </span><span class="lineNoCov">          0 :       h_off = (img_height - crop_size) / 2;</span>
<span class="lineNum">     285 </span><span class="lineNoCov">          0 :       w_off = (img_width - crop_size) / 2;</span>
<span class="lineNum">     286 </span>            :     }
<span class="lineNum">     287 </span>            :     cv::Rect roi(w_off, h_off, crop_size, crop_size);
<span class="lineNum">     288 </span><span class="lineNoCov">          0 :     cv_cropped_img = cv_img(roi);</span>
<span class="lineNum">     289 </span>            :   } else {
<span class="lineNum">     290 </span><span class="lineNoCov">          0 :     CHECK_EQ(img_height, height);</span>
<span class="lineNum">     291 </span><span class="lineNoCov">          0 :     CHECK_EQ(img_width, width);</span>
<span class="lineNum">     292 </span>            :   }
<span class="lineNum">     293 </span>            : 
<span class="lineNum">     294 </span><span class="lineNoCov">          0 :   CHECK(cv_cropped_img.data);</span>
<span class="lineNum">     295 </span>            : 
<span class="lineNum">     296 </span><span class="lineNoCov">          0 :   Dtype* transformed_data = transformed_blob-&gt;mutable_cpu_data();</span>
<span class="lineNum">     297 </span>            :   int top_index;
<span class="lineNum">     298 </span><span class="lineNoCov">          0 :   for (int h = 0; h &lt; height; ++h) {</span>
<span class="lineNum">     299 </span>            :     const uchar* ptr = cv_cropped_img.ptr&lt;uchar&gt;(h);
<span class="lineNum">     300 </span>            :     int img_index = 0;
<span class="lineNum">     301 </span><span class="lineNoCov">          0 :     for (int w = 0; w &lt; width; ++w) {</span>
<span class="lineNum">     302 </span><span class="lineNoCov">          0 :       for (int c = 0; c &lt; img_channels; ++c) {</span>
<span class="lineNum">     303 </span><span class="lineNoCov">          0 :         if (do_mirror) {</span>
<span class="lineNum">     304 </span><span class="lineNoCov">          0 :           top_index = (c * height + h) * width + (width - 1 - w);</span>
<span class="lineNum">     305 </span>            :         } else {
<span class="lineNum">     306 </span><span class="lineNoCov">          0 :           top_index = (c * height + h) * width + w;</span>
<span class="lineNum">     307 </span>            :         }
<span class="lineNum">     308 </span>            :         // int top_index = (c * height + h) * width + w;
<span class="lineNum">     309 </span><span class="lineNoCov">          0 :         Dtype pixel = static_cast&lt;Dtype&gt;(ptr[img_index++]);</span>
<span class="lineNum">     310 </span><span class="lineNoCov">          0 :         if (has_mean_file) {</span>
<span class="lineNum">     311 </span><span class="lineNoCov">          0 :           int mean_index = (c * img_height + h_off + h) * img_width + w_off + w;</span>
<span class="lineNum">     312 </span><span class="lineNoCov">          0 :           transformed_data[top_index] =</span>
<span class="lineNum">     313 </span><span class="lineNoCov">          0 :             (pixel - mean[mean_index]) * scale;</span>
<span class="lineNum">     314 </span>            :         } else {
<span class="lineNum">     315 </span><span class="lineNoCov">          0 :           if (has_mean_values) {</span>
<span class="lineNum">     316 </span><span class="lineNoCov">          0 :             transformed_data[top_index] =</span>
<span class="lineNum">     317 </span><span class="lineNoCov">          0 :               (pixel - mean_values_[c]) * scale;</span>
<span class="lineNum">     318 </span>            :           } else {
<span class="lineNum">     319 </span><span class="lineNoCov">          0 :             transformed_data[top_index] = pixel * scale;</span>
<span class="lineNum">     320 </span>            :           }
<span class="lineNum">     321 </span>            :         }
<span class="lineNum">     322 </span>            :       }
<span class="lineNum">     323 </span>            :     }
<span class="lineNum">     324 </span>            :   }
<span class="lineNum">     325 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     326 </span>            : #endif  // USE_OPENCV
<span class="lineNum">     327 </span>            : 
<span class="lineNum">     328 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     329 </span><span class="lineNoCov">          0 : void DataTransformer&lt;Dtype&gt;::Transform(Blob&lt;Dtype&gt;* input_blob,</span>
<span class="lineNum">     330 </span>            :                                        Blob&lt;Dtype&gt;* transformed_blob) {
<span class="lineNum">     331 </span><span class="lineNoCov">          0 :   const int crop_size = param_.crop_size();</span>
<span class="lineNum">     332 </span>            :   const int input_num = input_blob-&gt;num();
<span class="lineNum">     333 </span>            :   const int input_channels = input_blob-&gt;channels();
<span class="lineNum">     334 </span>            :   const int input_height = input_blob-&gt;height();
<span class="lineNum">     335 </span>            :   const int input_width = input_blob-&gt;width();
<span class="lineNum">     336 </span>            : 
<span class="lineNum">     337 </span><span class="lineNoCov">          0 :   if (transformed_blob-&gt;count() == 0) {</span>
<span class="lineNum">     338 </span>            :     // Initialize transformed_blob with the right shape.
<span class="lineNum">     339 </span><span class="lineNoCov">          0 :     if (crop_size) {</span>
<span class="lineNum">     340 </span><span class="lineNoCov">          0 :       transformed_blob-&gt;Reshape(input_num, input_channels,</span>
<span class="lineNum">     341 </span>            :                                 crop_size, crop_size);
<span class="lineNum">     342 </span>            :     } else {
<span class="lineNum">     343 </span><span class="lineNoCov">          0 :       transformed_blob-&gt;Reshape(input_num, input_channels,</span>
<span class="lineNum">     344 </span>            :                                 input_height, input_width);
<span class="lineNum">     345 </span>            :     }
<span class="lineNum">     346 </span>            :   }
<span class="lineNum">     347 </span>            : 
<span class="lineNum">     348 </span>            :   const int num = transformed_blob-&gt;num();
<span class="lineNum">     349 </span>            :   const int channels = transformed_blob-&gt;channels();
<span class="lineNum">     350 </span>            :   const int height = transformed_blob-&gt;height();
<span class="lineNum">     351 </span>            :   const int width = transformed_blob-&gt;width();
<span class="lineNum">     352 </span>            :   const int size = transformed_blob-&gt;count();
<span class="lineNum">     353 </span>            : 
<span class="lineNum">     354 </span><span class="lineNoCov">          0 :   CHECK_LE(input_num, num);</span>
<span class="lineNum">     355 </span><span class="lineNoCov">          0 :   CHECK_EQ(input_channels, channels);</span>
<span class="lineNum">     356 </span><span class="lineNoCov">          0 :   CHECK_GE(input_height, height);</span>
<span class="lineNum">     357 </span><span class="lineNoCov">          0 :   CHECK_GE(input_width, width);</span>
<span class="lineNum">     358 </span>            : 
<span class="lineNum">     359 </span>            : 
<span class="lineNum">     360 </span><span class="lineNoCov">          0 :   const Dtype scale = param_.scale();</span>
<span class="lineNum">     361 </span><span class="lineNoCov">          0 :   const bool do_mirror = param_.mirror() &amp;&amp; Rand(2);</span>
<span class="lineNum">     362 </span>            :   const bool has_mean_file = param_.has_mean_file();
<span class="lineNum">     363 </span>            :   const bool has_mean_values = mean_values_.size() &gt; 0;
<span class="lineNum">     364 </span>            : 
<span class="lineNum">     365 </span>            :   int h_off = 0;
<span class="lineNum">     366 </span>            :   int w_off = 0;
<span class="lineNum">     367 </span><span class="lineNoCov">          0 :   if (crop_size) {</span>
<span class="lineNum">     368 </span><span class="lineNoCov">          0 :     CHECK_EQ(crop_size, height);</span>
<span class="lineNum">     369 </span><span class="lineNoCov">          0 :     CHECK_EQ(crop_size, width);</span>
<span class="lineNum">     370 </span>            :     // We only do random crop when we do training.
<span class="lineNum">     371 </span><span class="lineNoCov">          0 :     if (phase_ == TRAIN) {</span>
<span class="lineNum">     372 </span><span class="lineNoCov">          0 :       h_off = Rand(input_height - crop_size + 1);</span>
<span class="lineNum">     373 </span><span class="lineNoCov">          0 :       w_off = Rand(input_width - crop_size + 1);</span>
<span class="lineNum">     374 </span>            :     } else {
<span class="lineNum">     375 </span><span class="lineNoCov">          0 :       h_off = (input_height - crop_size) / 2;</span>
<span class="lineNum">     376 </span><span class="lineNoCov">          0 :       w_off = (input_width - crop_size) / 2;</span>
<span class="lineNum">     377 </span>            :     }
<span class="lineNum">     378 </span>            :   } else {
<span class="lineNum">     379 </span><span class="lineNoCov">          0 :     CHECK_EQ(input_height, height);</span>
<span class="lineNum">     380 </span><span class="lineNoCov">          0 :     CHECK_EQ(input_width, width);</span>
<span class="lineNum">     381 </span>            :   }
<span class="lineNum">     382 </span>            : 
<span class="lineNum">     383 </span><span class="lineNoCov">          0 :   Dtype* input_data = input_blob-&gt;mutable_cpu_data();</span>
<span class="lineNum">     384 </span><span class="lineNoCov">          0 :   if (has_mean_file) {</span>
<span class="lineNum">     385 </span><span class="lineNoCov">          0 :     CHECK_EQ(input_channels, data_mean_.channels());</span>
<span class="lineNum">     386 </span><span class="lineNoCov">          0 :     CHECK_EQ(input_height, data_mean_.height());</span>
<span class="lineNum">     387 </span><span class="lineNoCov">          0 :     CHECK_EQ(input_width, data_mean_.width());</span>
<span class="lineNum">     388 </span><span class="lineNoCov">          0 :     for (int n = 0; n &lt; input_num; ++n) {</span>
<span class="lineNum">     389 </span><span class="lineNoCov">          0 :       int offset = input_blob-&gt;offset(n);</span>
<span class="lineNum">     390 </span><span class="lineNoCov">          0 :       caffe_sub(data_mean_.count(), input_data + offset,</span>
<span class="lineNum">     391 </span>            :             data_mean_.cpu_data(), input_data + offset);
<span class="lineNum">     392 </span>            :     }
<span class="lineNum">     393 </span>            :   }
<span class="lineNum">     394 </span>            : 
<span class="lineNum">     395 </span><span class="lineNoCov">          0 :   if (has_mean_values) {</span>
<span class="lineNum">     396 </span><span class="lineNoCov">          0 :     CHECK(mean_values_.size() == 1 || mean_values_.size() == input_channels) &lt;&lt;</span>
<span class="lineNum">     397 </span><span class="lineNoCov">          0 :      &quot;Specify either 1 mean_value or as many as channels: &quot; &lt;&lt; input_channels;</span>
<span class="lineNum">     398 </span><span class="lineNoCov">          0 :     if (mean_values_.size() == 1) {</span>
<span class="lineNum">     399 </span><span class="lineNoCov">          0 :       caffe_add_scalar(input_blob-&gt;count(), -(mean_values_[0]), input_data);</span>
<span class="lineNum">     400 </span>            :     } else {
<span class="lineNum">     401 </span><span class="lineNoCov">          0 :       for (int n = 0; n &lt; input_num; ++n) {</span>
<span class="lineNum">     402 </span><span class="lineNoCov">          0 :         for (int c = 0; c &lt; input_channels; ++c) {</span>
<span class="lineNum">     403 </span><span class="lineNoCov">          0 :           int offset = input_blob-&gt;offset(n, c);</span>
<span class="lineNum">     404 </span><span class="lineNoCov">          0 :           caffe_add_scalar(input_height * input_width, -(mean_values_[c]),</span>
<span class="lineNum">     405 </span>            :             input_data + offset);
<span class="lineNum">     406 </span>            :         }
<span class="lineNum">     407 </span>            :       }
<span class="lineNum">     408 </span>            :     }
<span class="lineNum">     409 </span>            :   }
<span class="lineNum">     410 </span>            : 
<span class="lineNum">     411 </span><span class="lineNoCov">          0 :   Dtype* transformed_data = transformed_blob-&gt;mutable_cpu_data();</span>
<span class="lineNum">     412 </span>            : 
<span class="lineNum">     413 </span><span class="lineNoCov">          0 :   for (int n = 0; n &lt; input_num; ++n) {</span>
<span class="lineNum">     414 </span><span class="lineNoCov">          0 :     int top_index_n = n * channels;</span>
<span class="lineNum">     415 </span>            :     int data_index_n = n * channels;
<span class="lineNum">     416 </span><span class="lineNoCov">          0 :     for (int c = 0; c &lt; channels; ++c) {</span>
<span class="lineNum">     417 </span><span class="lineNoCov">          0 :       int top_index_c = (top_index_n + c) * height;</span>
<span class="lineNum">     418 </span><span class="lineNoCov">          0 :       int data_index_c = (data_index_n + c) * input_height + h_off;</span>
<span class="lineNum">     419 </span><span class="lineNoCov">          0 :       for (int h = 0; h &lt; height; ++h) {</span>
<span class="lineNum">     420 </span><span class="lineNoCov">          0 :         int top_index_h = (top_index_c + h) * width;</span>
<span class="lineNum">     421 </span><span class="lineNoCov">          0 :         int data_index_h = (data_index_c + h) * input_width + w_off;</span>
<span class="lineNum">     422 </span><span class="lineNoCov">          0 :         if (do_mirror) {</span>
<span class="lineNum">     423 </span><span class="lineNoCov">          0 :           int top_index_w = top_index_h + width - 1;</span>
<span class="lineNum">     424 </span><span class="lineNoCov">          0 :           for (int w = 0; w &lt; width; ++w) {</span>
<span class="lineNum">     425 </span><span class="lineNoCov">          0 :             transformed_data[top_index_w-w] = input_data[data_index_h + w];</span>
<span class="lineNum">     426 </span>            :           }
<span class="lineNum">     427 </span>            :         } else {
<span class="lineNum">     428 </span><span class="lineNoCov">          0 :           for (int w = 0; w &lt; width; ++w) {</span>
<span class="lineNum">     429 </span><span class="lineNoCov">          0 :             transformed_data[top_index_h + w] = input_data[data_index_h + w];</span>
<span class="lineNum">     430 </span>            :           }
<span class="lineNum">     431 </span>            :         }
<span class="lineNum">     432 </span>            :       }
<span class="lineNum">     433 </span>            :     }
<span class="lineNum">     434 </span>            :   }
<span class="lineNum">     435 </span><span class="lineNoCov">          0 :   if (scale != Dtype(1)) {</span>
<span class="lineNum">     436 </span>            :     DLOG(INFO) &lt;&lt; &quot;Scale: &quot; &lt;&lt; scale;
<span class="lineNum">     437 </span><span class="lineNoCov">          0 :     caffe_scal(size, scale, transformed_data);</span>
<span class="lineNum">     438 </span>            :   }
<span class="lineNum">     439 </span><span class="lineNoCov">          0 : }</span>
<span class="lineNum">     440 </span>            : 
<span class="lineNum">     441 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     442 </span><span class="lineCov">      12109 : vector&lt;int&gt; DataTransformer&lt;Dtype&gt;::InferBlobShape(const Datum&amp; datum) {</span>
<span class="lineNum">     443 </span><span class="lineCov">      12109 :   if (datum.encoded()) {</span>
<span class="lineNum">     444 </span>            : #ifdef USE_OPENCV
<span class="lineNum">     445 </span><span class="lineNoCov">          0 :     CHECK(!(param_.force_color() &amp;&amp; param_.force_gray()))</span>
<span class="lineNum">     446 </span>            :         &lt;&lt; &quot;cannot set both force_color and force_gray&quot;;
<span class="lineNum">     447 </span><span class="lineNoCov">          0 :     cv::Mat cv_img;</span>
<span class="lineNum">     448 </span><span class="lineNoCov">          0 :     if (param_.force_color() || param_.force_gray()) {</span>
<span class="lineNum">     449 </span>            :     // If force_color then decode in color otherwise decode in gray.
<span class="lineNum">     450 </span><span class="lineNoCov">          0 :       cv_img = DecodeDatumToCVMat(datum, param_.force_color());</span>
<span class="lineNum">     451 </span>            :     } else {
<span class="lineNum">     452 </span><span class="lineNoCov">          0 :       cv_img = DecodeDatumToCVMatNative(datum);</span>
<span class="lineNum">     453 </span>            :     }
<span class="lineNum">     454 </span>            :     // InferBlobShape using the cv::image.
<span class="lineNum">     455 </span><span class="lineNoCov">          0 :     return InferBlobShape(cv_img);</span>
<span class="lineNum">     456 </span>            : #else
<span class="lineNum">     457 </span>            :     LOG(FATAL) &lt;&lt; &quot;Encoded datum requires OpenCV; compile with USE_OPENCV.&quot;;
<span class="lineNum">     458 </span>            : #endif  // USE_OPENCV
<span class="lineNum">     459 </span>            :   }
<span class="lineNum">     460 </span><span class="lineCov">      12109 :   const int crop_size = param_.crop_size();</span>
<span class="lineNum">     461 </span>            :   const int datum_channels = datum.channels();
<span class="lineNum">     462 </span>            :   const int datum_height = datum.height();
<span class="lineNum">     463 </span>            :   const int datum_width = datum.width();
<span class="lineNum">     464 </span>            :   // Check dimensions.
<span class="lineNum">     465 </span><span class="lineCov">      12109 :   CHECK_GT(datum_channels, 0);</span>
<span class="lineNum">     466 </span><span class="lineCov">      12109 :   CHECK_GE(datum_height, crop_size);</span>
<span class="lineNum">     467 </span><span class="lineCov">      12109 :   CHECK_GE(datum_width, crop_size);</span>
<span class="lineNum">     468 </span>            :   // Build BlobShape.
<span class="lineNum">     469 </span><span class="lineCov">      12109 :   vector&lt;int&gt; shape(4);</span>
<span class="lineNum">     470 </span><span class="lineCov">      12109 :   shape[0] = 1;</span>
<span class="lineNum">     471 </span><span class="lineCov">      12109 :   shape[1] = datum_channels;</span>
<span class="lineNum">     472 </span><span class="lineCov">      12109 :   shape[2] = (crop_size)? crop_size: datum_height;</span>
<span class="lineNum">     473 </span><span class="lineCov">      12109 :   shape[3] = (crop_size)? crop_size: datum_width;</span>
<span class="lineNum">     474 </span><span class="lineCov">      12109 :   return shape;</span>
<span class="lineNum">     475 </span>            : }
<span class="lineNum">     476 </span>            : 
<span class="lineNum">     477 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     478 </span><span class="lineNoCov">          0 : vector&lt;int&gt; DataTransformer&lt;Dtype&gt;::InferBlobShape(</span>
<span class="lineNum">     479 </span>            :     const vector&lt;Datum&gt; &amp; datum_vector) {
<span class="lineNum">     480 </span><span class="lineNoCov">          0 :   const int num = datum_vector.size();</span>
<span class="lineNum">     481 </span><span class="lineNoCov">          0 :   CHECK_GT(num, 0) &lt;&lt; &quot;There is no datum to in the vector&quot;;</span>
<span class="lineNum">     482 </span>            :   // Use first datum in the vector to InferBlobShape.
<span class="lineNum">     483 </span><span class="lineNoCov">          0 :   vector&lt;int&gt; shape = InferBlobShape(datum_vector[0]);</span>
<span class="lineNum">     484 </span>            :   // Adjust num to the size of the vector.
<span class="lineNum">     485 </span><span class="lineNoCov">          0 :   shape[0] = num;</span>
<span class="lineNum">     486 </span><span class="lineNoCov">          0 :   return shape;</span>
<span class="lineNum">     487 </span>            : }
<span class="lineNum">     488 </span>            : 
<a name="489"><span class="lineNum">     489 </span>            : #ifdef USE_OPENCV</a>
<span class="lineNum">     490 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     491 </span><span class="lineNoCov">          0 : vector&lt;int&gt; DataTransformer&lt;Dtype&gt;::InferBlobShape(const cv::Mat&amp; cv_img) {</span>
<span class="lineNum">     492 </span><span class="lineNoCov">          0 :   const int crop_size = param_.crop_size();</span>
<span class="lineNum">     493 </span>            :   const int img_channels = cv_img.channels();
<span class="lineNum">     494 </span><span class="lineNoCov">          0 :   const int img_height = cv_img.rows;</span>
<span class="lineNum">     495 </span><span class="lineNoCov">          0 :   const int img_width = cv_img.cols;</span>
<span class="lineNum">     496 </span>            :   // Check dimensions.
<span class="lineNum">     497 </span><span class="lineNoCov">          0 :   CHECK_GT(img_channels, 0);</span>
<span class="lineNum">     498 </span><span class="lineNoCov">          0 :   CHECK_GE(img_height, crop_size);</span>
<span class="lineNum">     499 </span><span class="lineNoCov">          0 :   CHECK_GE(img_width, crop_size);</span>
<span class="lineNum">     500 </span>            :   // Build BlobShape.
<span class="lineNum">     501 </span><span class="lineNoCov">          0 :   vector&lt;int&gt; shape(4);</span>
<span class="lineNum">     502 </span><span class="lineNoCov">          0 :   shape[0] = 1;</span>
<span class="lineNum">     503 </span><span class="lineNoCov">          0 :   shape[1] = img_channels;</span>
<span class="lineNum">     504 </span><span class="lineNoCov">          0 :   shape[2] = (crop_size)? crop_size: img_height;</span>
<span class="lineNum">     505 </span><span class="lineNoCov">          0 :   shape[3] = (crop_size)? crop_size: img_width;</span>
<span class="lineNum">     506 </span><span class="lineNoCov">          0 :   return shape;</span>
<span class="lineNum">     507 </span>            : }
<span class="lineNum">     508 </span>            : 
<span class="lineNum">     509 </span>            : template&lt;typename Dtype&gt;
<span class="lineNum">     510 </span><span class="lineNoCov">          0 : vector&lt;int&gt; DataTransformer&lt;Dtype&gt;::InferBlobShape(</span>
<span class="lineNum">     511 </span>            :     const vector&lt;cv::Mat&gt; &amp; mat_vector) {
<span class="lineNum">     512 </span><span class="lineNoCov">          0 :   const int num = mat_vector.size();</span>
<span class="lineNum">     513 </span><span class="lineNoCov">          0 :   CHECK_GT(num, 0) &lt;&lt; &quot;There is no cv_img to in the vector&quot;;</span>
<span class="lineNum">     514 </span>            :   // Use first cv_img in the vector to InferBlobShape.
<span class="lineNum">     515 </span><span class="lineNoCov">          0 :   vector&lt;int&gt; shape = InferBlobShape(mat_vector[0]);</span>
<span class="lineNum">     516 </span>            :   // Adjust num to the size of the vector.
<span class="lineNum">     517 </span><span class="lineNoCov">          0 :   shape[0] = num;</span>
<span class="lineNum">     518 </span><span class="lineNoCov">          0 :   return shape;</span>
<span class="lineNum">     519 </span>            : }
<span class="lineNum">     520 </span>            : #endif  // USE_OPENCV
<a name="521"><span class="lineNum">     521 </span>            : </a>
<span class="lineNum">     522 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">     523 </span><span class="lineCov">          4 : void DataTransformer&lt;Dtype&gt;::InitRand() {</span>
<span class="lineNum">     524 </span>            :   const bool needs_rand = param_.mirror() ||
<span class="lineNum">     525 </span><span class="lineCov">          4 :       (phase_ == TRAIN &amp;&amp; param_.crop_size());</span>
<span class="lineNum">     526 </span><span class="lineCov">          4 :   if (needs_rand) {</span>
<span class="lineNum">     527 </span><span class="lineNoCov">          0 :     const unsigned int rng_seed = caffe_rng_rand();</span>
<span class="lineNum">     528 </span><span class="lineNoCov">          0 :     rng_.reset(new Caffe::RNG(rng_seed));</span>
<span class="lineNum">     529 </span>            :   } else {
<span class="lineNum">     530 </span>            :     rng_.reset();
<span class="lineNum">     531 </span>            :   }
<span class="lineNum">     532 </span><span class="lineCov">          4 : }</span>
<a name="533"><span class="lineNum">     533 </span>            : </a>
<span class="lineNum">     534 </span>            : template &lt;typename Dtype&gt;
<span class="lineNum">     535 </span><span class="lineNoCov">          0 : int DataTransformer&lt;Dtype&gt;::Rand(int n) {</span>
<span class="lineNum">     536 </span><span class="lineNoCov">          0 :   CHECK(rng_);</span>
<span class="lineNum">     537 </span><span class="lineNoCov">          0 :   CHECK_GT(n, 0);</span>
<span class="lineNum">     538 </span>            :   caffe::rng_t* rng =
<span class="lineNum">     539 </span><span class="lineNoCov">          0 :       static_cast&lt;caffe::rng_t*&gt;(rng_-&gt;generator());</span>
<span class="lineNum">     540 </span><span class="lineNoCov">          0 :   return ((*rng)() % n);</span>
<span class="lineNum">     541 </span>            : }
<span class="lineNum">     542 </span>            : 
<a name="543"><span class="lineNum">     543 </span>            : INSTANTIATE_CLASS(DataTransformer);</a>
<span class="lineNum">     544 </span>            : 
<span class="lineNum">     545 </span><span class="lineCov">          3 : }  // namespace caffe</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.12</a></td></tr>
  </table>
  <br>

</body>
</html>
